package com.xing.controller;

import com.xing.Utils.Result;
import com.xing.dto.LiveRoomDTO;
import com.xing.dto.LiveRoomSaveDTO;
import com.xing.dto.LiveRoomUpdateDTO;
import com.xing.service.LiveRoomService;
import com.xing.utils.PageData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "直播间管理服务")
@RestController
@RequestMapping(value = "/liveRoom")
public class LiveRoomController {

    @Autowired
    private LiveRoomService roomService;


    @Operation(summary = "分页获取直播间信息")
    @GetMapping(value = "/getLiveRoomByPage")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result getLiveRoomByPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageData<LiveRoomDTO> liveRoomDtoList = roomService.getLiveRoomByPage(pageNum, pageSize);
        return new Result().ok(liveRoomDtoList);
    }


    @Operation(summary = "根据主播id获取直播间信息")
    @GetMapping(value = "/getLiveRoom")
    @PreAuthorize("hasAnyAuthority('admin','live')")
    public Result getLiveRoomByAnchorId(@RequestParam Long anchorId) {
        LiveRoomDTO liveRoomDTO = roomService.getLiveRoomByAnchorId(anchorId);
        return new Result().ok(liveRoomDTO);
    }


    @Operation(summary = "根据房间号获取直播间信息")
    @GetMapping(value = "/getLiveRoomByRoomNumber")
    public Result getLiveRoomByRoomNumber(@RequestParam Long roomNumber) {
        LiveRoomDTO liveRoomDTO = roomService.getLiveRoomByRoomNumber(roomNumber);
        return new Result().ok(liveRoomDTO);
    }


    @Operation(summary = "新增直播间信息")
    @PostMapping(value = "/saveLiveRoom")
    @PreAuthorize("hasAnyAuthority('admin','live')")
    public Result saveLiveRoom(@RequestBody LiveRoomSaveDTO liveRoomSaveDTO) {
        return roomService.saveLiveRoom(liveRoomSaveDTO);
    }


    @Operation(summary = "根据房间id修改直播间信息")
    @PostMapping(value = "/updateLiveRoom")
    @PreAuthorize("hasAnyAuthority('admin','live')")
    public Result updateLiveRoomByRoomId(@RequestBody LiveRoomUpdateDTO liveRoomUpdateDTO) {
        return roomService.updateLiveRoomByRoomId(liveRoomUpdateDTO);
    }


    @Operation(summary = "封禁直播间")
    @DeleteMapping(value = "/banLiveRoom")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result banLiveRoomByRoomId(@RequestParam Long liveRoomId) {
        return roomService.banLiveRoomByRoomId(liveRoomId);
    }


    @Operation(summary = "解禁直播间")
    @DeleteMapping(value = "/liftBanLiveRoom")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result liftBanLiveRoomByRoomId(@RequestParam Long liveRoomId) {
        return roomService.liftBanLiveRoomByRoomId(liveRoomId);
    }


    @Operation(summary = "注销直播间")
    @DeleteMapping(value = "/deleteLiveRoom")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result deleteLiveRoomByRoomId(@RequestParam Long liveRoomId) {
        return roomService.deleteLiveRoomByRoomId(liveRoomId);
    }

}
